﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebUI.UserControls;
using HRM.Entity;
using HRM.BIZ;

namespace WebUI.Pages
{
    public partial class LeaveTypeManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadData();
            }
        }

        protected void LoadData()
        {
            LeaveTypeBiz leaveBiz = new LeaveTypeBiz();
            ucLeaveTypeManagement.DataSource = leaveBiz.GetAll();
            ucLeaveTypeManagement.LoadItemList();
        }

        protected void ucLeaveTypeManagement_AddItem(object sender, ItemManagementEventArgs e)
        {
            LeaveTypeBiz leaveBiz = new LeaveTypeBiz();
            LeaveType leave = new LeaveType();
            leave.Name = e.Name;
            leaveBiz.Add(leave);
            (Master as DefaultMasterPage).RunStartupScript("displayMessage('Thêm thành công')");
            ucLeaveTypeManagement.SetActionPanelVisible(false);
            LoadData();
        }

        protected void ucLeaveTypeManagement_SaveEditItem(object sender, ItemManagementEventArgs e)
        {
            LeaveTypeBiz leaveBiz = new LeaveTypeBiz();
            LeaveType leave = leaveBiz.GetByID(e.ID);
            if (leave != null)
            {
                leave.Name = e.Name;
                leaveBiz.Update(leave);
                (Master as DefaultMasterPage).RunStartupScript("displayMessage('Cập nhật thành công')");
                ucLeaveTypeManagement.SetActionPanelVisible(false);
                LoadData();
            }
        }

        protected void ucLeaveTypeManagement_DeleteItem(object sender, ItemManagementEventArgs e)
        {
            LeaveTypeBiz leaveBiz = new LeaveTypeBiz();
            leaveBiz.Delete(e.ID);
            LoadData();
        }
    }
}
